package com.stork.cms.service;

import java.io.IOException;
import java.net.SocketException;
import java.util.ArrayList;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.stork.sms.service.marklist.MarkListItems;

public class ServiceCall {
	
	public  ServiceCall(){
	
		
	}
	
	private static final String SOAP_ACTION = "http://tempuri.org/getmarks";
	private static final String METHOD_NAME = "getmarks";
	private static final String NAMESPACE = "http://tempuri.org/";
	private static final String URL = "http://10.0.2.2:22679/smsservice/webmethods.asmx";
	
	 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
	 PropertyInfo properties=new PropertyInfo();
	  
	    
	    HttpTransportSE httpTransport = new HttpTransportSE(URL,1000*60);
	    
	    GsonBuilder gsonbuilder=new GsonBuilder();
	    Gson gson=null;
	    
	    String getresponse=null;
	    public ArrayList<String> Marks=new ArrayList<String>();
	    String[] marksValues;
	    /*String Regnumber=null;
	    String ExamsName=null;*/
	    
	    public MarkListItems GetMarks(String username)
	    {
	    	properties.name="Studentid";
	       	properties.type=PropertyInfo.STRING_CLASS;
	       	request.addProperty(properties,username);
	       	
	       
	       	
	       try
	       {
	    	   
	       	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	        envelope.dotNet = true;

	        envelope.setOutputSoapObject(request);
	        httpTransport.call(SOAP_ACTION, envelope);
	        SoapPrimitive result2=(SoapPrimitive) envelope.getResponse();
	        Log.i("result111111111111", result2.toString());
	        getresponse=result2.toString();
	        
	        gson=gsonbuilder.create();
	        
	        
	        MarkListItems Marksdetails=gson.fromJson(getresponse, MarkListItems.class);
	        Log.w("class call", "callllllllllllllllllllllllllllll");
//	        Log.w("LoginDetails",logindetails.toString());
	        //Log.w("LoginDetails111111111111",logindetails.getForgetpassword().toString());	        
	        Marks.add(Marksdetails.getCode());
	        Marks.add(Marksdetails.getMessage());
	        Marks.add(Marksdetails.getMarks().getName());
	        Marks.add(Marksdetails.getMarks().getRollNumber());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(0).getExamName());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(0).getEnglish());	        
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(0).getTamil());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(0).getTotal());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(0).getGrade());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(1).getExamName());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(1).getEnglish());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(1).getTamil());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(1).getTotal());
	        Marks.add(Marksdetails.getMarks().getMarkDetails().get(1).getGrade());
	       
	        marksValues=Marks.toArray(new String[Marks.size()]);     
	        return Marksdetails;
	       }
	       catch(SocketException se)
	       {
	    	   se.printStackTrace();
	       }
	       catch(XmlPullParserException xml)
	       {
	    	   xml.printStackTrace(); 
	       } catch (IOException e) {
			// TODO Auto-generated catch block
	    	   e.printStackTrace();
		}
		return null;
	       
	    }
	   

}
